package com.example.springbase.test.ConditionalOnMissingBean;

import com.example.springbase.test.AutowireMode.ConfigurationTest1;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ConditionalOnMissingBean
 *
 * @author zhouxianfeng
 * @date 2021-4-15
 */
@Configuration
@AutoConfigureBefore(ConfigurationTest1.class)
public class Conditional {

    @Bean
    public PersonMapper p1Mapper() {
        return new PersonMapper("p1");
    }

    @Bean
    @ConditionalOnMissingBean(PersonMapper.class)
    public PersonMapper p2Mapper() {
        return new PersonMapper("p2");
    }
}
